﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<List<PhysicalEquation.Models.SubjectModel>>" %>
<%@ Import Namespace="PhysicalEquation.Models" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Index
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<% Html.EnableClientValidation(); %>

<span style="font-size: 1.75em;">Subjects</span>
<img src="../../Content/Images/addEquationButton.png" alt="add new subject" title="add new subject" id="addNewSubject" class="addItemButton"/>
<br/>
<br/>
<table id="subjectsTable">
    <tr>
        <th style="display: none;">Id</th>
        <th>Nume</th>
        <th>Description</th>
        <th>Author</th>
    </tr>
    <%foreach(var item in Model) { %>
    <tr>
        <td style="display: none;"><%:item.Id%></td>
        <td><%:Html.ActionLink(item.Name, "index", "Equation", new{subjectId = item.Id}, null)%> </td>
        <td><%:item.Description%></td>
        <td><%:item.UserName%></td>
    </tr>
    <% } %>
</table>

<div title="subject" id="subjectDialogDiv">
    
    <%using(Ajax.BeginForm("AddSubject", "Subject", new AjaxOptions()
                                                        {
                                                            HttpMethod = "POST",
                                                            InsertionMode = InsertionMode.InsertAfter,
                                                            UpdateTargetId = "subjectsTable",
                                                            OnSuccess = "_onSuccess"
                                                        }))
        {%>
        <% Html.RenderPartial("AddSubjectView", new PhysicalEquation.Models.SubjectModel(){Name = "", Description = ""}); %>
        <% }%>
    </div>
</asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderID="FeaturedContent" runat="server">
</asp:Content>

<asp:Content ID="Content4" ContentPlaceHolderID="ScriptsSection" runat="server">
   <script language="javascript" type="text/javascript">
           $(document).ready(function () {
               $("#subjectDialogDiv").dialog({
                   autoOpen: false,
                   height: 300,
                   width: 350,
                   modal: true,
                   show: "fade",
                   hide: "fade",
                   buttons: {
                    "Add": function () {
                        _onAddSubject();
                    },
                    "Cancel": function () {
                        $(this).dialog("close");
                    }
                }
               });
               $("#addNewSubject").click(function () {
                   $("#subjectDialogDiv").dialog("open");
                   return false;
               });
           });

           var _onAddSubject = function (e) {
               $.validator.unobtrusive.parse(document);
               $("#submitNewSubject").click();
           };

           var _onSuccess = function() {
               $("#subjectDialogDiv").dialog("close");
           };
    </script>
</asp:Content>
